package com.bskj.kuaifu.controller;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class AreaCodeMain {
	public static void main(String[] args) throws Exception {
		String sql = "insert into t_area_info (area_code,area_name) values ('%s','%s')";
		String url = "jdbc:mysql://localhost:3306/kuaifu?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8";
		String user = "root";
		String password = "";
		Class.forName("com.mysql.jdbc.Driver");
		Connection connection = DriverManager.getConnection(url, user, password);
		Statement st = connection.createStatement();
		BufferedReader br = new BufferedReader(
				new InputStreamReader(new FileInputStream(new File("F:\\aaa.txt")), "GBK"));
		String str = "";
		while ((str = br.readLine()) != null) {
			str = repaceSpace(str);
			if ("".equals(str))
				continue;
			String[] strs = str.split(" ");
			String code = strs[0];
			String name = strs[1];
			String finalSql = String.format(sql, code,name);
			System.out.println(finalSql);
			st.executeUpdate(finalSql);
		}
		
		br.close();
	}

	private static String repaceSpace(String str) {
		Pattern p = Pattern.compile("\\s+");
		Matcher m = p.matcher(str);
		return m.replaceAll(" ");
	}
}
